import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 导入对应的路由组件
import page from '../components/map_location/MapPage.vue'
import CubePage from '../components/cubeinfo/CubePage.vue'
import CubeInfo from '../components/cubeinfo/CubeInfo.vue'
import CubeBookingOrder from '../components/cubeinfo/CubeBookingOrder.vue'
import CubeAliPay from '../components/cubeinfo/CubeAliPay.vue'
import LoginPage from '../components/login/LoginPage.vue'
import Login from '../components/login/Login.vue'
import PhoneLogin from '../components/login/PhoneLogin.vue'
import Register from '../components/login/Register.vue'
import BookingInfo from '../components/myBookingInfo/BookingInfo.vue'
import PersonalPage from '../components/personalCenter/PersonalPage.vue'
import PersonInfo from '../components/personalCenter/PersonInfo.vue'
import UserAddPlate from '../components/personalCenter/UserAddPlate.vue'
import UpdatePhoneNumber from '../components/personalCenter/UpdatePhoneNumber.vue'
import UpdateUserPass from '../components/personalCenter/UpdateUserPass.vue'
import About from '../components/about/About.vue'
import OpenMember from '../components/personalCenter/OpenMember.vue'



const router = new VueRouter({
    // 匹配路由规则
    routes: [
        { path: "/", component: page, name: "index" },
        { path: "/CubePage", redirect: "/CubePage/CubeInfo" },
        {
            path: "/CubePage", component: CubePage,
            beforeEnter: (to, from, next) => {
                if (sessionStorage.getItem('cubelibrarytoken') == null) {
                    next({
                        path: "/LoginPage",
                        query: { redirect: to.fullPath },
                    });
                } else {
                    next();
                }
            },
            children: [
                { path: "CubeInfo", component: CubeInfo, name: "CubeInfo" },
                { path: "CubeBookingOrder", component: CubeBookingOrder, name: "CubeBookingOrder" },
                { path: "CubePay", component: CubeAliPay, name: "CubeAliPay" },
            ]
        },

        { path: "/LoginPage", redirect: "/LoginPage/Login" },
        {
            path: "/LoginPage", component: LoginPage,
            children: [
                { path: "Login", component: Login },
                { path: "register", component: Register },
                { path: "phoneLogin", component: PhoneLogin }
            ]
        },

        { path: "/BookingInfo", component: BookingInfo },

        { path: "/PersonalPage", redirect: "/PersonalPage/PersonInfo" },
        {
            path: "/PersonalPage", component: PersonalPage,
            children: [
                { path: "PersonInfo", component: PersonInfo },
                { path: "UserAddPlate", component: UserAddPlate },
                { path: "UpdatePhoneNumber", component: UpdatePhoneNumber },
                { path: "UpdateUserPass", component: UpdateUserPass },
                { path: "OpenMember", component: OpenMember }
            ]
        },
        { path: "/About", component: About }
    ],

})


export default router;